package com.tianlu.store.controller;
 
import com.tianlu.store.entity.ScoreDetail;
import com.tianlu.store.service.ScoreDetailService;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import java.util.Objects;
import javax.annotation.Resource;
import java.util.List;
import com.tianlu.store.common.PageResult;
import com.tianlu.store.common.ResponseResult;
import com.tianlu.store.common.ResultCode;
import com.tianlu.store.common.IdGen;
 
/**
 * @Author 梁东烂
 * @Desc 积分明细表(ScoreDetail)表控制层
 * @Date 2023-04-11 15:22:10
 */
@Api(tags = "积分明细表")
@RestController
@RequestMapping("/api/scoreDetail")
@RequiredArgsConstructor
public class ScoreDetailController {
	@Resource
    private ScoreDetailService scoreDetailService;

	@ApiOperation("积分明细表列表(分页）接口")
    @PostMapping("/findPage")
    public ResponseResult<PageResult<ScoreDetail>> findPage(@RequestBody ScoreDetail scoreDetail) {
        return ResponseResult.success(scoreDetailService.findPage(scoreDetail));
    }
	
	@ApiOperation("积分明细表列表(不分页）接口")
    @PostMapping("/findList")
    public ResponseResult<List<ScoreDetail>> findList(@RequestBody ScoreDetail scoreDetail) {
        return ResponseResult.success(scoreDetailService.findList(scoreDetail));
    }
	
	@ApiOperation("查看积分明细表接口")
    @GetMapping(value = "/detail")
    public ResponseResult<ScoreDetail> detail(@RequestParam Long id) {
        return ResponseResult.success(scoreDetailService.getById(id));
    }

	@ApiOperation("添加积分明细表接口")
    @PostMapping("/save")
    public ResponseResult<Boolean> save(@RequestBody ScoreDetail scoreDetail) {
        scoreDetail.setId(IdGen.snowflakeId());
        return ResponseResult.success(scoreDetailService.save(scoreDetail));
    }
	
	@ApiOperation("修改积分明细表接口")
    @PostMapping("/update")
    public ResponseResult<Boolean> update(@RequestBody ScoreDetail scoreDetail) {
        if (Objects.isNull(scoreDetail.getId())) {
            return ResponseResult.fail(ResultCode.CODE_400, "ID不能为空");
        }
        return ResponseResult.success(scoreDetailService.updateById(scoreDetail));
    }
	
	@ApiOperation("删除积分明细表接口")
    @PostMapping("/deleteByIds")
    public ResponseResult<Boolean> deleteByIds(@RequestParam List<Long> ids) {
        return ResponseResult.success(scoreDetailService.removeByIds(ids));
    }
 
}
